# 本文件代码用于项目的性能分析
import mvplytool
import cProfile, pstats


def test():
    filepath = './model/书架.ply'
    savepath = './model/out.ply'
    model = mvplytool.load(filepath)
    model2 = mvplytool.tool.optimizeModel(model)
    mvplytool.tool.save(model2,savepath)
    print('优化完成')
    print(model.info)
    print(model2.info)

if __name__ == '__main__':
    print('开始')
    profileName = 'log.prof'
    profile = cProfile.Profile()
    profile.enable()    # 开始收集性能分析数据
    test()  # 执行代码
    profile.disable()   # 停止收集性能分析数据
    # Sort stat by internal time.
    sortby = "tottime"
    ps = pstats.Stats(profile).sort_stats(sortby)
    ps.dump_stats(profileName)


    # 之后可以在命令行中使用snakeviz log.prof进行可视化(pip install snakeviz)